package com.code.enums;

import com.code.exception.CodeGenerateException;

import java.util.stream.Stream;

public enum CodeGenerateType {

    PERSISTENCE("PERSISTENCE", 0),
    MODEL("MODEL", 1),
    FILTER("FILTER", 2),
    ENTITY("ENTITY", 3),
    MAPPER("MAPPER", 4),
    MAPPER_XML("MAPPER_XML", 5),
    REPOSITORY("REPOSITORY", 6),
    REPOSITORY_IMPL("REPOSITORY_IMPL", 7),
    SERVICE("SERVICE", 8),
    SERVICE_IMPL("SERVICE_IMPL", 9),
    REQUEST("REQUEST", 10),
    QUERY_REQUEST("QUERY_REQUEST", 11),
    PAGINATION_REQUEST("PAGINATION_REQUEST", 12),
    CONTROLLER("CONTROLLER", 13),
    TESTER("TESTER", 14),

    API_JS("API_JS", 15),

    INDEX("INDEX", 16)

    ;

    private final String name;
    private final int value;

    CodeGenerateType(String name, int value) {
        this.name = name;
        this.value = value;
    }

    public static CodeGenerateType of(final int value) {
        return Stream.of(values())
            .filter(codeGenerateType -> codeGenerateType.getValue() == value)
            .findFirst()
            .orElseThrow(() -> new CodeGenerateException("不支持的代码生成类型!"));
    }

    public String getName() {
        return name;
    }

    public int getValue() {
        return value;
    }

}
